import { Form, Select } from 'antd';
import React from 'react';

// 知识说明
// value 是 key
// text 是 value
// key -> value

// 参数说明
// model { id, name }
export const DisabledSelectForm = props => {
  let { 
    title, 
    field, 
    message, // 错误message
    form,

    initialValue, 

    defaultValue,
    defaultKey,
    defaultText,

    model, /** currentXiangmu */ 

    modelGetter,
  } = props

  if (modelGetter) {
    model = modelGetter();
  }

  if (model) {
    initialValue = model.id;
    
    defaultValue = model.id;
    defaultKey = model.id;
    defaultText = model.name;
  }

  return (
    <Form.Item label={title} labelCol={{ span: 5 }} wrapperCol={{ span: 15 }}>
      {form.getFieldDecorator(field, {
        initialValue,
        rules: [{ required: true, message }],
      })(
        <Select disabled>
          <Option value={defaultValue} key={defaultKey}>{defaultText}</Option>
        </Select>,
        // list2options({
        //   list: userProjectList,
        //   placeholder: '请选择项目名称',
        //   key: 'id',
        // }),
      )}
    </Form.Item>
  );
}